﻿using System;
using System.Data;
using TimKen.DataEntity;
using System.Collections.Generic;

namespace TimKen.BussLogic
{
    /// <summary>
    /// 留言板业务逻辑操作类
    /// </summary>
    public class MessageBoardManager
    {
        private readonly DataAccess.MessageBoardDAO dal = new TimKen.DataAccess.MessageBoardDAO();
        public MessageBoardManager()
        { }
        #region  成员方法

        /// <summary>
        /// 得到最大ID
        /// </summary>
        public int GetMaxId()
        {
            return dal.GetMaxId();
        }

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int MessageID)
        {
            return dal.Exists(MessageID);
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public void Add(MessageBoard model)
        {
            dal.Add(model);
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public void Update(MessageBoard model)
        {
            dal.Update(model);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public void Delete(int MessageID)
        {

            dal.Delete(MessageID);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public  MessageBoard GetModel(int MessageID)
        {

            return dal.GetModel(MessageID);
        }
 
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            return dal.GetList(strWhere);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<MessageBoard> GetModelList(string strWhere)
        {
            DataSet ds = dal.GetList(strWhere);
            List<MessageBoard> modelList = new List<MessageBoard>();
            int rowsCount = ds.Tables[0].Rows.Count;
            if (rowsCount > 0)
            {
                MessageBoard model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new MessageBoard();
                    if (ds.Tables[0].Rows[0]["MessageID"].ToString() != "")
                    {
                        model.MessageID = int.Parse(ds.Tables[0].Rows[0]["MessageID"].ToString());
                    }
                    model.Phone = ds.Tables[0].Rows[0]["Phone"].ToString();
                    model.Fax = ds.Tables[0].Rows[0]["Fax"].ToString();
                    model.Comments = ds.Tables[0].Rows[0]["Comments"].ToString();
                    model.IP = ds.Tables[0].Rows[0]["IP"].ToString();
                    if (ds.Tables[0].Rows[0]["CreateDate"].ToString() != "")
                    {
                        model.CreateDate = DateTime.Parse(ds.Tables[0].Rows[0]["CreateDate"].ToString());
                    }
                    model.Title = ds.Tables[0].Rows[0]["Title"].ToString();
                    model.UserName = ds.Tables[0].Rows[0]["UserName"].ToString();
                    model.Email = ds.Tables[0].Rows[0]["Email"].ToString();
                    model.Company = ds.Tables[0].Rows[0]["Company"].ToString();
                    model.Address = ds.Tables[0].Rows[0]["Address"].ToString();
                    model.City = ds.Tables[0].Rows[0]["City"].ToString();
                    model.State = ds.Tables[0].Rows[0]["State"].ToString();
                    model.PostalCode = ds.Tables[0].Rows[0]["PostalCode"].ToString();
                    modelList.Add(model);
                }
            }
            return modelList;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetAllList()
        {
            return GetList("");
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(int PageSize, int PageIndex, string strWhere)
        {
            return dal.GetList(PageSize, PageIndex, strWhere);
        }

        #endregion  成员方法
    }
}
